<?php

namespace app\common\validate\airQuality;

use think\Validate;

class AirQualityWeatherAnalysisValidate extends Validate
{
    protected $rule = [
        'station_id' => 'require',
        'start_time' => 'require',
        'end_time'   => 'require',
        'region_id'  => 'require',
        'date_type'  => 'require|check_date:date_type参数错误',
        'aqi_level'  => 'require',
        'look_time'  => 'require',
    ];
    protected $message = [
        'station_id.require' => '请选择站点',
        'start_time.require' => '请选择开始时间',
        'end_time.require'   => '请选择结束时间',
        'region_id.require'  => '请选择排序类型',
        'date_type.require'  => '请选择日期类型',
        'aqi_level.require'  => '请选择空气质量等级',
        'look_time.require'  => '请选择时间',

    ];
    protected $scene = [
        'airQualityWeatherAnalysis'   => ['station_id', 'date_type', 'start_time', 'end_time'],
        'airQualityRankingStatistics' => ['region_id', 'date_type', 'look_time'],
        'primaryPollutantRate'        => ['station_id', 'date_type', 'start_time', 'end_time', 'aqi_level'],
    ];

    // 自定义验证规则

    /**
     * 日期类型验证
     * @author yy by 2019/5/9
     * @param $value
     * @param $rule
     * @param array $data
     * @param $name
     * @param $description
     * @return bool
     */
    protected function check_date($value, $rule, $data = [], $name, $description)
    {
        if (!in_array(strtolower($value), ['year', 'month', 'day'])) {
            return $rule;
        } else {
            return true;
        }
    }

}